@extends('home.layoutBlade.CenterLayout')

@section('content')

    <div class="user_right">
        <div class="user_tab">
            <div class="tab_title list_title clearfix">

                <h1 class="tab_btn active"  value='5'>所有订单</h1>
                <h1 href="" class="tab_btn" value="0" >待付款</h1>
                <h1 href="" class="tab_btn" value='1'>待发货</h1>
                <h1 href="" class="tab_btn" value='2'>待收货</h1>
                <h1 href="" class="tab_btn" value='3'>待评价</h1>

            </div>
            <div class="tab_body">
                <div class="tab_list" style="display:block;">
                    <div class="all_list">
                        <div class="all_operation clearfix">


                        </div>
                        <div class="all_title">
                            <ul class="clearfix">
                                <li class="all_title_name">商品名称</li>
                                <li class="all_title_unit">单价（元）</li>
                                <li class="all_title_number">数量</li>
                                <li class="all_title_total">总价（元）</li>
                                <li class="all_title_state clearfix">
                                    <span class="state_txt">状态</span>
                                
                                </li>
                                <li class="all_title_opetation">操作</li>
                            </ul>
                        </div>
                <div id="order_list_data">

        <div class="all_table" xmlns="http://www.w3.org/1999/html">
           
        </div>
    

    </div>
<!-- 页码 -->
<div class="page_number">
    <ul class="clearfix">
        <li class="page_btn prev disable">
            <a href="javascript:;" title="上一页" class="clearfix"><i></i><span>上一页</span></a>
        </li>
        <li class="page_num active"><a href="javascript:;">1</a></li>                             
        <li class="page_btn next disable">
            <a href="javascript:;" title="下一页" class="clearfix"><i></i><span>下一页</span></a>
        </li>
        <li class="page_total">共1页</li>
        <li class="page_goto">到第<input id="page_goto_index" value="1" type="text">页</li>
        <li class="page_sure"><input onclick="page_sure()" style="cursor: pointer;" value="确定" type="button"></li>
                
    </ul>
</div>



@endsection

<script type="text/javascript">

        window.onload = function()
        {
            $('h1').css('cursor', 'pointer');


            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                 }
            });


           //单击事件
            $('h1').on('click',function(){

                ajaxOn($(this));

             });//button 单击

            ajaxOn($('h1').eq(1));

                function ajaxOn(h)
                {
                    h.css('backgroundColor', '#fff');
                    h.css('color', '#D62F26');
                    h.siblings().css('backgroundColor', '#EEEEEE');
                    h.siblings().css('color', 'black');
                    //获取状态
                    var val = h.attr('value');
                    console.log(val);
                    var item = '';

                    $.ajax({
                        type:'POST',
                        url:"{{ url('home/order/ajaxOrder') }}",
                        data:{status:val},
                        dataType:'json',
                        success:function(data)
                        {
                            // console.log(data);
                           if(data == null || data == '')
                           {
                                 $('.all_table').html("<h5>没有相应条件的信息</h5>");
                           }

                            $(data).each(function(i,result){
                                
                                //将时间戳转化为00-00-00 00:00:00格式
                                function getDate(tm){
                                    var time=new Date(parseInt(tm) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ")
                                    return time;
                                }

                                var addtime = getDate(result.addtime);
                                
                                //向表格中添加单元格
                                var status = '';
                                var method = '';

                                if(result.post_status == 0)
                                {
                                    status = '待付款';
                                    

                                }else if(result.post_status == 1)
                                {
                                    status = "待发货";

                                }else if(result.post_status == 2)
                                {
                                    status = "<a class='sure' href='/home/order/sure/"+result.id+"'>确认收货</a>";

                                }else if(result.post_status == 3)
                                {
                                    status = "<a href='{{}}/'"+result.id" class='sure'>待评价</a>";
                                }else if (result.post_status == 6)
                                {
                                    status = "退款中";
                                }else if (result.post_status == 7)
                                {
                                    status = "已完成";
                                }


                                if(result.post_method == 0)
                                {
                                    method = '在线支付';
                                }

                                //判断如果状态处于待付款,显示取消订单,立即支付
                                var cancelorder = '';

                                var pay = '';

                                if(result.post_status == 0)
                                {
                                    
                                    cancelorder = "<a href='/home/order/delete/"+result.id+"' class='cancelorder'>取消订单</a>";
                                    pay = "<a class='dsix_boxa_title_btn' href='/home/order/orderpay/"+result.id+"' target='_blank' style='color: red'>立即支付</a>";
                                }else if(result.post_status == 2)
                                {
                                    pay = "<a class='dsix_boxa_title_btn' href='/home/order/saleReturn/"+result.id+"' target='_blank' style='color: red'>申请退款</a>";
                                }


                                item += "<div class='table_list'><div class='table_title clearfix'><a href='javascript:;'class='list_sel clearfix order_checkbox'><input disabled='disabled' type='checkbox'></a><div class='list_sel clearfix'><i></i><span>"+addtime+" &nbsp;&nbsp;</span></div><span class='table_listnum'>订单编号："+result.post_number+"</span></div><table cellspacing='0'cellpadding='0' border='0'><tbody><tr><td width='669'><div class='table_main'><ul class='clearfix table_pro'><li class='table_proimg'><a href=''><img src='/uploads/goods_pic/"+result.logo+"'></a></li><li class='table_proname' style='height: auto;line-height: 18px;padding-top: 40px'><p><a class='id' href=''>"+result.goods_name+"</a><br></p></li><li class='table_proprice'>"+result.goods_price+"</li><li class='table_pronum'>"+result.goods_number+"</li></ul></div></td><td width='111'><span class='table_price'>"+(result.goods_price*result.goods_number).toFixed(2)+"</span><br><span class='table_state'>"+method+"</td><td width='111'><a class='post_status'>"+status+"</a><br>"+pay+"</td><td width='111' class='caozuo'><a href='/home/order/orderdetail/"+result.goods_id+"'>查看详情</a><br>"+cancelorder+"</td></tr></tbody></table></div>";

                                $('.all_table').html(item);

                                $('.cancelorder').css('cursor', 'pointer');  

                                $('.sure').css('cursor', 'pointer'); 

                            });//遍历json数组

                            
                        },//success

                        error:function()
                        {
                            alert('异常');
                        }
                    });//ajax 分类

                }                    
        }
           
</script>
